package com.dhl.fin.api.domain;

import com.dhl.fin.api.common.domain.BasicDomain;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.util.List;

/**
 * Created by CuiJianbo on 2020.02.27.
 */

@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "t_tree")
public class Tree extends BasicDomain {

    public Tree() {
    }

    public Tree(Long id, String title, String code, Tree parent) {
        this.id = id;
        this.title = title;
        this.code = code;
        this.parent = parent;
    }

    public Tree(Long id) {
        super.setId(id);
    }


    @Column(columnDefinition = "varchar(50) ")
    private String title;


    @Column(columnDefinition = "varchar(50)")
    private String code;

    @Column(columnDefinition = "int default 1 ")
    private Integer orderNum;

    @Column(columnDefinition = "bit default 1 ")
    private Boolean leaf;

    @Column(columnDefinition = "varchar(300)")
    private String parentLine;

    @ManyToOne
    @JoinColumn(name = "parent_id")
    private Tree parent;

    @OneToMany(mappedBy = "parent")
    private List<Tree> children;

    @Transient
    private List<Tree> childrenData;

    /**
     * 关联角色, 此节点存放的是action数据
     */
    @ManyToMany
    @JoinTable(name = "t_role_tree",
            joinColumns = {@JoinColumn(name = "tree_id")},
            inverseJoinColumns = {@JoinColumn(name = "role_id")})
    private List<Role> roles;


    @OneToOne
    @JoinColumn(name = "menu_id")
    private Menu menu;

    @OneToOne
    @JoinColumn(name = "action_id")
    private Action action;


}
